package com.example.springboottestgit.controller;

import com.example.springboottestgit.bean.CommonException;
import com.example.springboottestgit.bean.ResultMsg;
import com.example.springboottestgit.bean.vo.FileVO;
import com.example.springboottestgit.service.FileService;
import com.example.springboottestgit.service.InviteTenderService;
import com.example.springboottestgit.service.SubmitTenderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @description:智能招投标识别匹配系统
 * @author: ZZZ
 * @time: 2021/4/12 21:08
 */
@RestController
public class TenderController {
    @Autowired
    private InviteTenderService inviteTenderService;
    @Autowired
    private SubmitTenderService submitTenderService;
    @Autowired
    private FileService fileService;

    /**
     * 法律法规查询
     *
     * @return
     */

    @PostMapping("/law/query")
    public ResultMsg<List<FileVO>> lawQuery(@RequestBody List<Long> ids) {
        List<FileVO> list = inviteTenderService.lawQuery(ids);
        return ResultMsg.success(list);
    }


    /**
     * 招标文件上传
     *
     * @param list
     * @return
     */
    @PostMapping("/invite/tender/upload")
    public ResultMsg<Object> inviteTenderUpload(@RequestParam("file") List<MultipartFile> list) {
        for (MultipartFile multipartFile : list) {
            String fileName = multipartFile.getOriginalFilename();
            if (!fileName.endsWith(".docx")) {
                throw new CommonException("001001", "文件格式错误");
            }
        }
        List<Long> ids = fileService.inviteTenderUpload(list);
        return ResultMsg.success(ids.get(0));
    }

    /**
     * 投标文件上传
     *
     * @param list
     * @return
     */
    @PostMapping("/submit/tender/upload")
    public ResultMsg<Object> submitTenderUpload(@RequestParam("file") List<MultipartFile> list, @RequestParam("id") Long id) {
        for (MultipartFile multipartFile : list) {
            String fileName = multipartFile.getOriginalFilename();
            if (!fileName.endsWith(".docx")) {
                throw new CommonException("001001", "文件格式错误");
            }
        }
        fileService.submitTenderUpload(list, id);
        return ResultMsg.success();
    }

    /**
     * 招标文件技术要求查询
     *
     * @param id
     * @return
     */

    @GetMapping("/submit/tender/query")
    public ResultMsg<List<FileVO>> submitTenderQuery(long id) {
        List<FileVO> list = submitTenderService.submitTenderQuery(id);
        return ResultMsg.success(list);
    }

    @GetMapping("/submit/tender/delete")
    public ResultMsg<Object> submitTenderDelete(long id, long assId) {
        submitTenderService.submitTenderDelete(id, assId);
        return ResultMsg.success();
    }

}
